var userId = null;
var sys = sessionStorage.getItem("sys");

function initPage() {
	if(sys == 1) {
		$("#root").hide();
	}
	initSystem();
	showLoginInfo();
	$.ajax({
		url: "../g/service/Sample/getUserId",
		type:'POST',
		cache:false,
		async:false,
		dataType: "json",
		contentType:"application/json",
        success:function(data){
        	userId = data;
        	if(data != 0 && data != 1) {
				window.parent.location.href="../../index.html";
        	}
        }
	});
	$(".caidan").click(function(){
		$(".caidan").each(function(i,e){
			$(e).css("backgroundColor", "unset");
	    });
		$(this).css("backgroundColor", "#0079FE");
	});
};
function initSystem(){
	var sys = sessionStorage.getItem("sys");
	invoke_sys('getSystem', {sys:sys}, function(data){
		$("#logo_icon").attr('src',' ../images/'+data.data[0].logo_pic);
		$("#logo_title").text(data.data[0].logo_text);
		$('#logo_icon').click(function(){
			window.location.href="../../index.html";
		});
    });
};
//展示登陆用户信息
function showLoginInfo(){
	$.ajax({
		url: '../pv/login/loginInfo',
		type: "get",
		success:function(res){
			result = res;
			if (result != "") {
				$("#login_name").text(result);
			}else {
				$("#login").text("登录/注册");
				window.parent.location.href="login.html";
			}
		}
	})
}
function userMenu() {
	$("#rightPanel").show();
	$("#menuText").text("用户管理");
	$("#iframe").attr("src", "userManager.html");
}
function rootMenu() {
	$("#rightPanel").show();
	$("#menuText").text("权限管理");
	$("#iframe").attr("src", "rootManager.html");
}
function planMenu() {
	$("#rightPanel").show();
	$("#menuText").text("方案查看");
	$("#iframe").attr("src", "planCheckMenu.html");
}
function invoke_sys(url, args, callback){
	var r, op = {
			url: '../g/service/Sysconfig/' + url,
			type:'POST',
			cache:false,
			async:true,
			dataType:'json',
			data:args ? JSON.stringify(args) : null,
			contentType:"application/json"
		};
	if(typeof callback == 'function'){
		op.success = function(data){
			if(data.error)return alert(data.error);
			callback(data);
		}
	} else {
		op.async = false;
		op.success = function(data){
			r = data
		};
	}
	$.ajax(op);
	if(r)if(r.error){
		alert(r.error);
		return null;
	}
	return r;
};
